import { lazyHttpClient } from '@/http';
import { getConfig } from '@/utils';
import type { IApiGeovisRegeoMoreParams, IApiGeovisRegeoMoreRes } from './types';

const { SM_GEOVIS_TOKEN } = import.meta.env;

/** 逆地理编码查询 */
export const regeoMore = ({ points, radius = 1000, pageSize = 1, currentPage = 1, classify }: IApiGeovisRegeoMoreParams) => {
  const geovis = getConfig().appSettings.geovis;
  let paramsStr = `points=${encodeURIComponent(
    `${points.lng},${points.lat}`,
  )}&radius=${radius}&pageSize=${pageSize}&currentPage=${currentPage}`;
  if (classify) paramsStr += `&classify=${classify}`;
  return lazyHttpClient().get<IApiGeovisRegeoMoreRes>(`${geovis.url}/geo/v1/geocode/regeoMore?${paramsStr}`, {
    baseURL: '',
    headers: {
      Authorization: `Bearer ${SM_GEOVIS_TOKEN}`,
    },
  });
};
